<?php

/**
 * Baner form.
 *
 * @package    sf_portal
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class BanerForm extends BaseBanerForm
{
  public function configure()
  {
  			$c = new Criteria ( );	
		$c->addAnd ( FolderPeer::SCOPE, 3);
	
		
  	unset( 
  		$this['created_at'],  
  		$this['see'],
  		$this['click'],  
  		$this['user_id'], 
  		$this['updated_at'] 
  		);
  	
  		$arc = array();
  		$dd = $this->getObject()->getBaner2Folders();
  		foreach($dd as $d)
  		{
  			$arc[$d->getFolderId()]=$d->getFolderId();
  		}
  		
  		  $this->setWidgets(array(
      'id'          => new sfWidgetFormInputHidden(),
      'file_path'   => new inputBanerTag (  array (), array('mat_id'=>$this->object->getId()) ),
      'pub'         => new sfWidgetFormInputCheckbox(),
      'title'       => new sfWidgetFormInput(),
      'url'         => new sfWidgetFormInput(),
      'width'         => new sfWidgetFormInput(),
  	  'height'         => new sfWidgetFormInput(),	  
     
      'position_id' => new sfWidgetFormPropelChoice(array('model' => 'BanerPosition', 'add_empty' => false)),
      'material_id' => new sfWidgetFormInputHidden(),
  	  'checked_folder' => new myWidgetCheckedFolder (array(),array('mat'=>$this->object)),
  	 
    ));
  		
    /////привязка к регионам
  	    if(sfConfig::get('app_use_simple_region')==true)
	    {
	    	
	       $this->widgetSchema['region_id'] =  new sfWidgetFormPropelChoice(array('multiple' => false, 'expanded' => true, 'model' => 'Region', 'add_empty' => false));
	    }
	 //////   

	    
	     /////Каталоги
  	    if($this->object->getId()>0)
	    {
	    	
	       $this->widgetSchema['baner2_folder_list'] =  new sfUoWidgetPropelNestedList(
array(
'model'=>'Folder',
'criteria'=>$c,
'order_by'=>array('TreeLeft','asc'),
'js_transformer' => 'treeview_admin'
),
array('check_f'=>$arc,
'id_obj'=>$this->getObject()->getId(),
'url_del'=>'baner/del_folder',
'url_add'=>'baner/add_folder',
)
);
	    }
	 //////  
	    
	    
	    
	    
	    
    $this->validatorSchema['file_path'] = new sfValidatorFile(array(
        'required'   => false,
        'path'       => sfConfig::get('sf_web_dir').'/uploads/baner',
        'max_size'   => 380000, // 360 kB
        )); 
        
        
 
        
        
         $this->validatorSchema['material_id'] = new sfValidatorInteger(array('required' => false)); 
  	
        
         $this->validatorSchema->setOption('allow_extra_fields', true); 
  		 $this->widgetSchema->setNameFormat('baner[%s]');
    
  }
  
  
}
